package com.ly.web.controller.erp;

import com.ly.common.PageParam;
import com.ly.common.annotation.Log;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.KingInvoicePayableOtherEntity;
import com.ly.heart.domain.dto.KingInvoicePayableOtherDto;
import com.ly.heart.service.IKingInvoicePayableOtherService;
import com.ly.heart.service.king.PayableOtherPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:其他应付单
 * @Date Created in 1:16 2024-09-01
 * @return
 */
@Api (value = "KingInvoicePayableOther", tags = "其他应付单")
@RestController
@RequestMapping ("/heart/KingInvoicePayableOther")
public class KingInvoicePayableOtherController {

    @Resource
    private IKingInvoicePayableOtherService iKingInvoicePayableOtherService;
    @Resource
    private PayableOtherPushService payableOtherPushService;

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayableOther:list')")
    @GetMapping ("/list")
    @ApiOperation ("其他应付单列表")
    @Log (title = "其他应付单列表")
    public AjaxResult list (KingInvoicePayableOtherEntity kingInvoicePayableOtherEntity) {
        List<KingInvoicePayableOtherEntity> kingInvoicePayableOtherEntities = iKingInvoicePayableOtherService.selectKingInvoicePayableOtherEntityList ( kingInvoicePayableOtherEntity );
        Integer count = iKingInvoicePayableOtherService.queryCount ( kingInvoicePayableOtherEntity );
        PageParam p = new PageParam ();
        p.setRecords ( kingInvoicePayableOtherEntities ).setTotal ( count );
        return AjaxResult.success ( p );
    }

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayableOther:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("其他应付单列表详细信息")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( iKingInvoicePayableOtherService.selectKingInvoicePayableOtherEntityById ( id ) );
    }

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayableOther:add')")
    @Log (title = "暂存其他应付单", businessType = BusinessType.INSERT)
    @PostMapping ("draft")
    @ApiOperation ("暂存其他应付单")
    public AjaxResult draft (@RequestBody KingInvoicePayableOtherDto kingInvoicePayableOtherDto) {
        KingInvoicePayableOtherEntity kingInvoicePayableOtherEntity = kingInvoicePayableOtherDto.getKingInvoicePayableOtherEntity ();
        if ( StringUtils.isNotBlank ( kingInvoicePayableOtherEntity.getId () ) ) {
            return iKingInvoicePayableOtherService.updateKingInvoicePayableOtherEntity ( kingInvoicePayableOtherDto );
        }
        return iKingInvoicePayableOtherService.draft ( kingInvoicePayableOtherDto );
    }

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayableOther:add')")
    @Log (title = "提交其他应付单", businessType = BusinessType.INSERT)
    @PostMapping ("submit")
    @ApiOperation ("提交其他应付单")
    public AjaxResult submit (@RequestBody KingInvoicePayableOtherEntity kingInvoicePayableOtherEntity) {
        AjaxResult submit = iKingInvoicePayableOtherService.submit ( kingInvoicePayableOtherEntity );
        return submit;
    }

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayable:edit')")
    @Log (title = "修改其他应付单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改其他应付单")
    public AjaxResult edit (@RequestBody KingInvoicePayableOtherDto kingInvoicePayableOtherDto) {
        return iKingInvoicePayableOtherService.updateKingInvoicePayableOtherEntity ( kingInvoicePayableOtherDto );
    }

    @PreAuthorize ("@ss.hasPermi('heart:KingInvoicePayable:remove')")
    @Log (title = "删除其他应付单", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除其他应付单")
    public AjaxResult remove (@PathVariable String[] ids) {

        return iKingInvoicePayableOtherService.deleteKingInvoicePayableOtherEntityByIds ( ids );
    }

    @Log (title = "推送其他应付单")
    @GetMapping ("/send/{id}")
    @ApiOperation ("推送其他应付单")
    public AjaxResult send (@PathVariable String id) {
        KingInvoicePayableOtherEntity payableOtherEntity = new KingInvoicePayableOtherEntity ();
        payableOtherEntity.setId ( id );
        payableOtherPushService.push ( payableOtherEntity );
        return AjaxResult.success ("推送成功");
    }

    @Log (title = "付款单选择其他应付单")
    @GetMapping ("queryList")
    @ApiOperation ("付款单选择其他应付单")
    public AjaxResult queryList (KingInvoicePayableOtherEntity kingInvoicePayableOtherEntity) {

        return iKingInvoicePayableOtherService.queryList ( kingInvoicePayableOtherEntity );
    }

}
